package com.daxt.mapper.sys;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.daxt.model.service.archives.vo.ArchivesClass;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

public interface ArchivesClassMapper extends BaseMapper<ArchivesClass>{

    //给内蒙部署的时候需要使用，其它时候注释掉就行
	@Select("SELECT GROUP_CONCAT(hor.classNum SEPARATOR '·' ) as treeStr\n" +
            "    from archives_class hor\n" +
            "    where id in (\n" +
            " \t\t\tselect a.curr_id from (\n" +
            " \t\t\t\tSELECT @id AS curr_id\n" +
            " \t\t\t\t\t\t, (\n" +
            " \t\t\t\t\t\t\t\tSELECT @id := GROUP_CONCAT(parentId)\n" +
            " \t\t\t\t\t\t\t\tFROM archives_class\n" +
            " \t\t\t\t\t\t\t\tWHERE FIND_IN_SET(id, @id)\n" +
            " \t\t\t\t\t\t) AS p_ids, @l := @l + 1 AS LEVEL\n" +
            " \t\t\t\tFROM archives_class, (\n" +
            " \t\t\t\t\t\t\t\tSELECT @id := #{id}, @l := 0\n" +
            " \t\t\t\t\t\t) b\n" +
            " \t\t\t\tWHERE @id IS NOT NULL and @id !='' order by LEVEL DESC\n" +
            " \t\t\t) a\n" +
            "    );")
    String getTreeStr(long id);

    @Select("select c2.* \n" +
            "from archives_class c1 join archives_class c2\n" +
            "on c2.parentId=c1.id\n" +
            "where c2.className=#{className} and c1.className=#{parentClassName}")
	ArchivesClass nameGetClassName(String parentClassName,String className);
}